<template>
<div>
<div style="box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04); padding: 30px;height: 60%;width: 30%; margin:30px auto; ">
  <el-form ref="form" :model="form" label-width="80px" >
    <el-form-item label="电话号码">
      <el-input v-model="form.phone"></el-input>
    </el-form-item>
    <el-form-item label="真实姓名">
      <el-input v-model="form.realname"></el-input>
    </el-form-item>
    <el-form-item label="个性签名">
      <el-input v-model="form.signature"></el-input>
    </el-form-item>
    <el-form-item label="性别">
      <el-radio-group v-model="form.sex">
        <el-radio label="男"></el-radio>
        <el-radio label="女"></el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">修改信息</el-button>
      <el-button>取消</el-button>
      <el-link type="warning" style="margin-left: 20px;">修改密码?</el-link>
    </el-form-item>
  </el-form>
</div>


</div>
</template>

<script>
export default {
name: "info",
  data(){
    return {
      form: {
        phone: '',
        realname: '',
        signature: '',
        sex: '',
        delivery: false,
        type: [],
        resource: '',
        desc: ''
      }
    }
  },
  methods:{
    onSubmit(){
      var that= this
      let value=2
      if (this.form.sex=="男"){
        value=1
      }
      if (this.form.sex=="女"){
        value=0
      }
      axios.get(this.ip+ 'user/update', {
        params: {
          id:localStorage.getItem("id"),
          phone:this.form.phone,
          realname:this.form.realname,
          signature:this.form.signature,
          sex:value
        }
      })
        .then(function (response) {
          if (response.data==="修改成功"){
            localStorage.setItem("lastname", that.form.name);
            localStorage.setItem("pic", that.form.pic);
            that.$message({
              message:response.data,
              type:"success"
            })
          }else {
            that.$message({
              message:response.data,
              type:"error"
            })
          }

        })
        .catch(function (error) {
          console.log(error);
        });
    },
    async getInfo(){
      let res = await  axios(this.ip+"user/getUser?id="+localStorage.getItem("id"))
      this.form.phone=res.data.phone
      this.form.realname=res.data.realname
      this.form.signature=res.data.signature
      if (res.data.sex==0){
        this.form.sex= "女"
      }
      if (res.data.sex==1){
        this.form.sex= "男"
      }


    }
  },
  mounted() {
    this.getInfo()
  }
}
</script>

<style scoped>

</style>
